<?php
/**
 * Copyright (c) 2006-2008, PORTALIER Julien
 * http://featherphp.googlecode.com/
 * 
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

/**
 *  Performs restrictive checks on arrays.
 */
class Security
{
	/**
	 * Restricts keys in an array.
	 * 
	 * @param $data Array
	 * @param $allowed_keys Mixed
	 */
	function restrict_keys(&$data, $allowed_keys)
	{
		$allowed_keys = array_collection($allowed_keys);
		foreach(array_keys($data) as $k)
		{
			if (!in_array($k, $allowed_keys)) {
				unset($data[$k]);
			}
		}
	}
	
	/**
	 * Removes certain keys in an array.
	 * 
	 * @param $data Array
	 * @param $disallowed_keys Mixed
	 */
	function remove_keys(&$data, $disallowed_keys)
	{
		$disallowed_keys = array_collection($disallowed_keys);
		foreach(array_keys($data) as $k)
		{
			if (in_array($k, $disallowed_keys)) {
				unset($data[$k]);
			}
		}
	}
}
?>